package com.software.loginregister.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.software.loginregister.R;
import com.software.loginregister.adapter.HealthCardAdapter;
import com.software.loginregister.entity.HealthFood;

import java.util.ArrayList;
import java.util.List;

public class HealthCardActivity extends AppCompatActivity {
    private RecyclerView rvHealthFoods;
    private HealthCardAdapter adapter;
    private List<HealthFood> healthFoodList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_health_card);

        initViews();
        initData();
    }

    private void initViews() {
        // 修改为btn_health_card_back，与布局文件一致
        findViewById(R.id.btn_health_card_back).setOnClickListener(v -> finish());

        rvHealthFoods = findViewById(R.id.rv_health_foods);
        rvHealthFoods.setLayoutManager(new GridLayoutManager(this, 2));

        adapter = new HealthCardAdapter();
        rvHealthFoods.setAdapter(adapter);
    }

    private void initData() {
        healthFoodList = new ArrayList<>();
        // 添加模拟数据，修改构造方法调用，添加图片资源ID参数
        healthFoodList.add(new HealthFood("拉面", "关键食材：面粉，黄瓜，黑木耳...", R.drawable.img_1, 189));
        healthFoodList.add(new HealthFood("拉面", "关键食材：面粉，胡萝卜，青菜...", R.drawable.img_1, 189));
        healthFoodList.add(new HealthFood("拉面", "关键食材：面粉，生菜，番茄...", R.drawable.img_1, 189));
        healthFoodList.add(new HealthFood("拉面", "关键食材：面粉，蔬菜，调味料...", R.drawable.img_1, 189));

        adapter.setData(healthFoodList);
    }
}